package com.example.smartgreenhouse.aliyun_bailian;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
/**
 *阿里云百炼的服务，用于调用百炼AI的API
 */

@Service
public class BaiLianService {
    @Value("${aliyun.bailian.api.key}")
    private String apiKey;
    @Value("${aliyun.bailian.api.id}")
    private String apiId;

    public String callBaiLianApi(String input)
            throws ApiException, NoApiKeyException, InputRequiredException{
        ApplicationParam param = ApplicationParam.builder()
                .apiKey(apiKey)
                .appId(apiId)
                .prompt(input)
                .build();
        // 配置私网终端节点
        Application application = new Application("https://dashscope.aliyuncs.com/api/v1/");
        ApplicationResult result = application.call(param);
        return result.getOutput().getText();
    }
}
